package com.cykj.page01.servlet;

import com.cykj.page01.MyHttpRequest;
import com.cykj.page01.MyHttpResponse;
import com.cykj.page01.StaticResourceHandler;
import com.cykj.page01.anno.ServletMapping;

/**
 * @BelongsProject: HandTomcat
 * @BelongsPackage: com.cykj.page05.servlet
 * @Author: 阿隆
 * @CreateTime: 2025-10-29 20:54
 * @Description: 静态资源
 * @Version: 1.0
 */
@ServletMapping("/default")
public class DefaultServlet extends BaseServlet {
    @Override
    protected void doGet(MyHttpRequest httpRequest, MyHttpResponse httpResponse) {

    }

    @Override
    protected void doPost(MyHttpRequest httpRequest, MyHttpResponse httpResponse) {

    }

    @Override
    public void requestMethodHandler(MyHttpRequest httpRequest, MyHttpResponse httpResponse) {
        //动态拼接路径
        String resourcePath = "webapps" + httpRequest.getRequestUrl();

        //静态资源处理器
        StaticResourceHandler staticResourceHandler = new StaticResourceHandler(resourcePath);

        httpResponse.write(staticResourceHandler.getMedia(), staticResourceHandler.getFileByte());

    }
}